<template>
	<div style="position: relative">
		<search-form :query-form="params" :form-span="6" @refresh="refresh">
			<template #firstLine>
				<el-col :span="6" class="search-from-row">
					<el-form-item prop="tableName" label="表名称：">
						<el-input v-model="params.tableName" placeholder="表名称" />
					</el-form-item>
				</el-col>
				<el-col :span="6" class="search-from-row" />
				<el-col :span="6" class="search-from-row" />
			</template>
		</search-form>
		<div class="global-table-content">
			<div class="table-button-group">
				<el-button-group>
					<el-button type="primary" size="mini" @click="downloads">
						<el-icon>
							<download />
						</el-icon>
						批量下载
					</el-button>
					<el-button type="success" size="mini" @click="refresh">
						<el-icon>
							<refresh />
						</el-icon>
						刷新
					</el-button>
				</el-button-group>
			</div>
			<base-page
				ref="generationpage"
				:header-row-class-name="'my-table-heard'"
				:header-cell-class-name="'my-table-heard'"
				:row-class-name="'my-table-row'"
				:divclass="'tree-div-page'"
				:data-function="getData"
				:other-params="params"
			>
				<el-table-column type="selection" width="40px" />
				<el-table-column align="center" prop="tableName" label="表名" min-width="15%">
					<template #default="scope">
						<span>{{ scope.row.tableName }}</span>
					</template>
				</el-table-column>
				<el-table-column align="center" prop="tableComment" label="表描述" min-width="20%">
					<template #default="scope">
						<span>{{ scope.row.tableComment }}</span>
					</template>
				</el-table-column>
				<el-table-column align="center" prop="createTime" label="创建时间" min-width="20%">
					<template #default="scope">
						<span>{{ scope.row.createTime }}</span>
					</template>
				</el-table-column>
				<el-table-column align="center" prop="updateTime" label="更新时间" min-width="20%" sortable="custom">
					<template #default="scope">
						<span>{{ scope.row.updateTime }}</span>
					</template>
				</el-table-column>
				<el-table-column align="center" label="操作" min-width="25%">
					<template #default="scope">
						<el-button size="mini" type="primary" @click="download(scope.row.tableName)">
							<el-icon>
								<download />
							</el-icon>
							下载
						</el-button>
						<el-button size="mini" type="danger" @click="deleteForm(scope.$index, scope.row)">
							<el-icon>
								<delete />
							</el-icon>
							删除
						</el-button>
					</template>
				</el-table-column>
			</base-page>
		</div>
	</div>
</template>

<script lang="ts">
import { Options, Vue } from 'vue-class-component';
import { tool } from '@/api';
import BasePage from '@/components/page/BasePage';
import { WebApi } from '@/assets/model/httpconfig/WebApi';
import SearchForm from '@/components/page/SearchForm.vue';
@Options({
	components: {
		'base-page': BasePage,
		'search-form': SearchForm
	}
})
export default class UserPage extends Vue {
	public generation = new tool.generation();
	/**添加表单控制 */
	public params = {
		tableName: ''
	};
	mounted() {}
	/**获取列表数据 */
	getData(data: any) {
		return this.generation.selecttablepage(data);
	}
	/**重置搜素 */
	resetSearch() {
		let example: any = this.$refs['searchForm'];
		example.resetFields();
	}
	/**刷新 */
	public refresh() {
		let table: any = this.$refs.generationpage;
		table.refresh();
	}
	//下载文件
	download(tableName: any) {
		//this.generation.downtablecode(tableName)
		let a = document.createElement('a');
		a.href = WebApi.backstagePath + '/tool/gen/genCode/' + tableName;
		a.click();
	}
	downloads() {
		let table: any = this.$refs.generationpage;
		const selectRows = table.getSelectRows();
		let tablenames = '';
		for (let i = 0; i < selectRows.length; i++) {
			tablenames += selectRows[i].tableName + ',';
		}
		tablenames = tablenames.substring(0, tablenames.length - 1);
		let a = document.createElement('a');
		a.href = WebApi.backstagePath + '/tool/gen/batchGenCode?tables=' + tablenames;
		a.click();
	}
}
</script>
<style lang="scss"></style>
